home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 May / macformat-024.iso / Shareware City / Developers / Kant Pro source Folder / Kant Pro 1.1 ƒ / Shell ƒ / menus.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-19  |  17.5 KB  |  669 lines  |  [TEXT/MMCC]

  1. #include "menus.h"
  2. #include "graphics.h"
  3. #include "help.h"
  4. #include "environment.h"
  5. #include "error.h"
  6. #include "file interface.h"
  7. #include "resource utilities.h"
  8. #include "print meat.h"
  9. #include "text twiddling.h"
  10. #include "util.h"
  11. #include "graphics dispatch.h"
  12. #include "window layer.h"
  13. #include "program globals.h"
  14. #include "kant.h"
  15. #include "kantinuous.h"
  16. #include "kant load-save.h"
  17. #include "kant parser dispatch.h"
  18. #include "kant build files.h"
  19. #include "kant build meat.h"
  20. #include "kant build gui.h"
  21.  
  22. static    MenuHandle        gAppleMenu=0L;
  23. static    MenuHandle        gFileMenu=0L;
  24. static    MenuHandle        gEditMenu=0L;
  25. static    MenuHandle        gOptionsMenu=0L;
  26. static    MenuHandle        gModulesMenu=0L;
  27. static    MenuHandle        gInsertMenu=0L;
  28. MenuHandle        gBuildMenu=0L;
  29. static    MenuHandle        gSpeedMenu=0L;
  30.  
  31. #define NUM_MODULES        (CountMItems(gModulesMenu)-modules_first+1)
  32.  
  33. enum
  34. {
  35.     speedMenu = 200,
  36.     
  37.     appleMenu = 400, fileMenu, editMenu, optionsMenu, modulesMenu, insertMenu, buildMenu,
  38.     
  39.     aboutItem = 1, aboutMSGItem, otherMSGItem, helpPointerItem,
  40.     
  41.     newItem = 1, openItem, file_unused1, closeItem, saveItem, saveAsItem, file_unused2,
  42.         pageSetupItem, printItem, file_unused3, quitItem,
  43.     
  44.     undoItem = 1, edit_unused0, cutItem, copyItem, pasteItem, clearItem, edit_unused1, selectAllItem,
  45.     
  46.     resolveItem = 1, alwaysResolveItem, option_unused1, speedMenuPtr, option_unused3,
  47.         kantinuousItem,
  48.     
  49.     modules_default = 1, modules_other, modules_unused, modules_first,
  50.     
  51.     sectionItem = 1, paragraphItem, sentenceItem, mainClauseItem, introClauseItem,
  52.         throwawayClauseItem, proofItem, throwawaySentenceItem,
  53.     
  54.     build_new = 1, build_open, build_unused1, build_new_ref, build_new_instant,
  55.         build_edit_ref, build_delete_ref, build_unused2, build_show_instant,
  56.         build_show_all_instant, build_hide_all_instant,
  57.     
  58.     delay0Item = 1, delay6Item, delay12Item, delay30Item, delay60Item
  59. };
  60.  
  61. /*-----------------------------------------------------------------------------------*/
  62. /* internal stuff for menus.c                                                        */
  63.  
  64. static    void HandleAppleMenu(short menuItem);
  65. static    void HandleFileMenu(short menuItem);
  66. static    void HandleEditMenu(short menuItem, Boolean alreadyPassedThrough);
  67. static    void HandleOptionsMenu(short menuItem);
  68. static    void HandleModulesMenu(short menuItem);
  69. static    void HandleInsertMenu(short menuItem);
  70. static    void HandleBuildMenu(short menuItem);
  71. static    void HandleSpeedMenu(short menuItem);
  72. static    void EDItem(MenuHandle theMenu, short theItem, Boolean theCondition);
  73.  
  74. Boolean InitTheMenus(void)
  75. {
  76.     Handle            MBARHandle;
  77.     FSSpec            theFS;
  78.     
  79.     if ((MBARHandle=GetNewMBar(400))==0L)        /* sez which menus are in menu bar. */
  80.         return FALSE;
  81.     SetMenuBar(MBARHandle);                        /* set this to be THE menu bar to use. */
  82.     
  83.     if ((gAppleMenu=GetMHandle(appleMenu))==0L)    /* GetNewMBar also got menu handles of */
  84.         return FALSE;
  85.     if ((gFileMenu=GetMHandle(fileMenu))==0L)    /* every menu it includes, so just */
  86.         return FALSE;
  87.     if ((gEditMenu=GetMHandle(editMenu))==0L)    /* grab these handles and assign them */
  88.         return FALSE;
  89.     if ((gOptionsMenu=GetMHandle(optionsMenu))==0L)
  90.         return FALSE;
  91.     if ((gModulesMenu=GetMHandle(modulesMenu))==0L)
  92.         return FALSE;
  93.     if ((gInsertMenu=GetMHandle(insertMenu))==0L)
  94.         return FALSE;
  95.     if ((gBuildMenu=GetMHandle(buildMenu))==0L)
  96.         return FALSE;
  97.     if ((gSpeedMenu=GetMenu(speedMenu))==0L)
  98.         return FALSE;
  99.     
  100.     InsertMenu(gSpeedMenu, -1);
  101.     
  102.     AddResMenu(gAppleMenu, 'DRVR');                /* adds control panels to apple menu */
  103.     
  104.     if (BuildModulesList(gModulesMenu)!=noErr)
  105.     {
  106.         HandleError(kCantFindModulesFolder, FALSE, FALSE);
  107.         theFS.name[0]=0x00;
  108.         UseTheModule(&theFS, TRUE);    /* revert to built-in */
  109.     }
  110.     
  111.     if (!gUseDefault)
  112.         RebuildReferencesList();
  113.     
  114.     AdjustMenus();                                /* dim/enable/check/mark menus/items */
  115.     DrawMenuBar();                                /* draws the actual menu bar */
  116.     
  117.     return TRUE;
  118. }
  119.  
  120. void ShutDownTheMenus(void)
  121. {
  122.     gAppleMenu=(MenuHandle)SafeReleaseResource((Handle)gAppleMenu);
  123.     gFileMenu=(MenuHandle)SafeReleaseResource((Handle)gFileMenu);
  124.     gEditMenu=(MenuHandle)SafeReleaseResource((Handle)gEditMenu);
  125.     gOptionsMenu=(MenuHandle)SafeReleaseResource((Handle)gOptionsMenu);
  126.     gModulesMenu=(MenuHandle)SafeReleaseResource((Handle)gModulesMenu);
  127.     gInsertMenu=(MenuHandle)SafeReleaseResource((Handle)gInsertMenu);
  128.     gBuildMenu=(MenuHandle)SafeReleaseResource((Handle)gBuildMenu);
  129.     gSpeedMenu=(MenuHandle)SafeReleaseResource((Handle)gSpeedMenu);
  130. }
  131.  
  132. void AdjustMenus(void)
  133. {
  134.     short            kind;
  135.     WindowPtr        front, frontDoc, mainWindow, buildWindow;
  136.     Boolean            isRef;
  137.     Str255            theStr;
  138.     Boolean            gotone;
  139.     short            i;
  140.     unsigned char    *otherStr="\pOther...";
  141.     
  142.     front=FrontWindow();
  143.     kind=front ? ((WindowPeek)front)->windowKind : 0;
  144.     frontDoc=GetFrontDocumentWindow();
  145.     mainWindow=GetIndWindowPtr(kMainWindow);
  146.     buildWindow=GetIndWindowPtr(kBuildWindow);
  147.     isRef=RefHighlightedQQ(buildWindow);
  148.     
  149.     CheckItem(gOptionsMenu, alwaysResolveItem, gAlwaysResolve ? TRUE : FALSE);
  150.     CheckItem(gSpeedMenu, delay0Item, (gSpeedDelay==0));
  151.     CheckItem(gSpeedMenu, delay6Item, (gSpeedDelay==6));
  152.     CheckItem(gSpeedMenu, delay12Item, (gSpeedDelay==12));
  153.     CheckItem(gSpeedMenu, delay30Item, (gSpeedDelay==30));
  154.     CheckItem(gSpeedMenu, delay60Item, (gSpeedDelay==60));
  155.     
  156.     SetItem(gBuildMenu, build_edit_ref, isRef ? "\pEdit reference" : "\pEdit instantiation");
  157.     SetItem(gBuildMenu, build_delete_ref, isRef ? "\pDelete reference" : "\pDelete instantiation");
  158.     SetItem(gBuildMenu, build_show_instant, RefClosedQQ(buildWindow) ? "\pShow instantiations" :
  159.         "\pHide instantiations");
  160.     
  161.     SetItemMark(gModulesMenu, modules_default, gUseDefault ? '◊' : noMark);
  162.     SetItemMark(gModulesMenu, modules_other, noMark);
  163.         
  164.     gotone=gUseDefault;
  165.     for (i=0; i<NUM_MODULES; i++)
  166.     {
  167.         if (!gotone)
  168.         {
  169.             GetItem(gModulesMenu, i+modules_first, theStr);
  170.             if (Mymemcompare((Ptr)theStr, (Ptr)gModuleFS.name, theStr[0]+1))
  171.                 gotone=TRUE;
  172.             SetItemMark(gModulesMenu, i+modules_first, gotone ? '◊' : noMark);
  173.         }
  174.         else SetItemMark(gModulesMenu, i+modules_first, noMark);
  175.     }
  176.     
  177.     if (!gotone)
  178.     {
  179.         SetItemMark(gModulesMenu, modules_other, '◊');
  180.         Mymemcpy((Ptr)theStr, (Ptr)otherStr, otherStr[0]+1);
  181.         AppendStr255(theStr, "\p (");
  182.         AppendStr255(theStr, gModuleFS.name);
  183.         AppendStr255(theStr, "\p)");
  184.         SetItem(gModulesMenu, modules_other, theStr);
  185.     }
  186.     else SetItem(gModulesMenu, modules_other, "\pOther...");
  187.     
  188.     EDItem(gAppleMenu, 0, !gInProgress);
  189.     EDItem(gAppleMenu, aboutItem, !gInProgress);
  190.     EDItem(gAppleMenu, aboutMSGItem, !gInProgress);
  191.     EDItem(gAppleMenu, otherMSGItem, !gInProgress);
  192.     EDItem(gAppleMenu, helpPointerItem, !gInProgress);
  193.     EDItem(gFileMenu, 0, !gInProgress);
  194.     EDItem(gEditMenu, 0, !gInProgress);
  195.     EDItem(gOptionsMenu, 0, !gInProgress);
  196.     EDItem(gModulesMenu, 0, !gInProgress);
  197.     EDItem(gInsertMenu, 0, !gInProgress);
  198.     EDItem(gBuildMenu, 0, !gInProgress);
  199.     
  200.     if (gInProgress)
  201.         return;
  202.     
  203.     EDItem(gFileMenu, newItem, (mainWindow==0L));
  204.     EDItem(gFileMenu, openItem, (mainWindow==0L));
  205.     EDItem(gFileMenu, closeItem, front!=0L);
  206.     EDItem(gFileMenu, saveItem, (mainWindow!=0L) && (WindowHasLayer(mainWindow)) &&
  207.         (WindowIsModifiedQQ(mainWindow)));
  208.     EDItem(gFileMenu, saveAsItem, mainWindow!=0L);
  209.     EDItem(gFileMenu, pageSetupItem, TRUE);
  210.     EDItem(gFileMenu, printItem, (frontDoc!=0L) && (WindowHasLayer(frontDoc)) &&
  211.         (GetWindowTE(frontDoc)!=0L));
  212.     EDItem(gFileMenu, quitItem, TRUE);
  213.     
  214.     EDItem(gEditMenu, undoItem, kind<0);
  215.     EDItem(gEditMenu, cutItem, (frontDoc!=0L) && (frontDoc==mainWindow) && (AnyHighlightedQQ(frontDoc)));
  216.     EDItem(gEditMenu, copyItem, (frontDoc!=0L) && (frontDoc==mainWindow) && (AnyHighlightedQQ(frontDoc)));
  217.     EDItem(gEditMenu, pasteItem, (frontDoc!=0L) && (frontDoc==mainWindow) && (AnyTextInScrapQQ()));
  218.     EDItem(gEditMenu, clearItem, (frontDoc!=0L) && (frontDoc==mainWindow) && (AnyHighlightedQQ(frontDoc)));
  219.     EDItem(gEditMenu, selectAllItem, (frontDoc!=0L) && (frontDoc==mainWindow) && (AnyTextQQ(frontDoc)));
  220.     
  221.     EDItem(gOptionsMenu, resolveItem, (mainWindow!=0L));
  222.     EDItem(gOptionsMenu, speedMenuPtr, TRUE);
  223.     EDItem(gOptionsMenu, kantinuousItem, gUseDefault);
  224.     
  225.     EDItem(gBuildMenu, build_new, buildWindow==0L);
  226.     EDItem(gBuildMenu, build_open, buildWindow==0L);
  227.     EDItem(gBuildMenu, build_new_ref, buildWindow!=0L);
  228.     EDItem(gBuildMenu, build_new_instant, (buildWindow!=0L) && (AnyHighlightedQQ(buildWindow)));
  229.     EDItem(gBuildMenu, build_edit_ref, (buildWindow!=0L) && (AnyHighlightedQQ(buildWindow)));
  230.     EDItem(gBuildMenu, build_delete_ref, (buildWindow!=0L) && (AnyHighlightedQQ(buildWindow)));
  231.     EDItem(gBuildMenu, build_show_instant, (buildWindow!=0L) && (AnyHighlightedQQ(buildWindow)) && isRef);
  232.     EDItem(gBuildMenu, build_show_all_instant, (buildWindow!=0L) && (AnyTextQQ(buildWindow)));
  233.     EDItem(gBuildMenu, build_hide_all_instant, (buildWindow!=0L) && (AnyTextQQ(buildWindow)));
  234. }
  235.  
  236. void HandleMenu(long mSelect)
  237. {
  238.     short            menuID = HiWord(mSelect);
  239.     short            menuItem = LoWord(mSelect);
  240.     
  241.     switch (menuID)
  242.     {
  243.         case appleMenu:
  244.             HandleAppleMenu(menuItem);
  245.             break;
  246.         case fileMenu:
  247.             HandleFileMenu(menuItem);
  248.             break;    
  249.         case editMenu:
  250.             HandleEditMenu(menuItem, FALSE);
  251.             break;
  252.         case optionsMenu:
  253.             HandleOptionsMenu(menuItem);
  254.             break;
  255.         case modulesMenu:
  256.             HandleModulesMenu(menuItem);
  257.             break;
  258.         case insertMenu:
  259.             HandleInsertMenu(menuItem);
  260.             break;
  261.         case buildMenu:
  262.             HandleBuildMenu(menuItem);
  263.             break;
  264.         case speedMenu:
  265.             HandleSpeedMenu(menuItem);
  266.             break;
  267.     }
  268. }
  269.  
  270. void DoTheCloseThing(WindowPeek theWindow)
  271. /* a standard close procedure, called when "close" is chosen from File menu and when
  272.    a window is closed through its close box */
  273. {
  274.     short            kind;
  275.     
  276.     if (theWindow==0L)
  277.         return;
  278.     
  279.     kind = theWindow ? theWindow->windowKind : 0;
  280.     if (kind<0)        /* DA window or other system window */
  281.         CloseDeskAcc(kind);
  282.     else
  283.     {
  284.         if (WindowHasLayer((WindowPtr)theWindow))
  285.             CloseTheWindow((WindowPtr)theWindow);
  286.         else
  287.             DisposeWindow((WindowPtr)theWindow);
  288.         
  289.         AdjustMenus();
  290.     }
  291. }
  292.  
  293. static    void HandleAppleMenu(short menuItem)
  294. {
  295.     GrafPtr        savePort;
  296.     Str255        name;
  297.     
  298.     switch (menuItem)
  299.     {
  300.         case aboutItem:
  301.             if (!IndWindowExistsQQ(kAboutWindow))
  302.                 OpenTheIndWindow(kAboutWindow);
  303.             else
  304.                 MySelectWindow(GetIndWindowPtr(kAboutWindow));
  305.             break;
  306.         case aboutMSGItem:
  307.             if (!IndWindowExistsQQ(kAboutMSGWindow))
  308.                 OpenTheIndWindow(kAboutMSGWindow);
  309.             else
  310.                 MySelectWindow(GetIndWindowPtr(kAboutMSGWindow));
  311.             break;
  312.         case otherMSGItem:
  313.             if (!IndWindowExistsQQ(kOtherMSGWindow))
  314.                 OpenTheIndWindow(kOtherMSGWindow);
  315.             else
  316.                 MySelectWindow(GetIndWindowPtr(kOtherMSGWindow));
  317.             break;
  318.         case helpPointerItem:
  319.             if (!IndWindowExistsQQ(kHelpWindow))
  320.                 OpenTheIndWindow(kHelpWindow);
  321.             else
  322.                 MySelectWindow(GetIndWindowPtr(kHelpWindow));
  323.             break;
  324.         default:
  325.             if (menuItem > helpPointerItem+1)
  326.             {
  327.                 GetPort(&savePort);
  328.                 GetItem(gAppleMenu, menuItem, name);
  329.                 OpenDeskAcc(name);
  330.                 SetPort(savePort);
  331.             }
  332.             break;
  333.     }
  334. }
  335.  
  336. static    void HandleFileMenu(short menuItem)
  337. {
  338.     WindowPtr            theWindow;
  339.     TEHandle            hTE;
  340.     
  341.     switch (menuItem)
  342.     {
  343.         case newItem:
  344.             OpenTheIndWindow(kMainWindow);
  345.             break;
  346.         case openItem:
  347.             LoadSaveDispatch(TRUE, FALSE);
  348.             break;
  349.         case closeItem:
  350.             if ((theWindow=GetFrontDocumentWindow())!=0L)
  351.                 DoTheCloseThing((WindowPeek)theWindow);
  352.             else
  353.                 DoTheCloseThing((WindowPeek)FrontWindow());
  354.             break;
  355.         case saveItem:
  356.             LoadSaveDispatch(FALSE, TRUE);
  357.             break;
  358.         case saveAsItem:
  359.             LoadSaveDispatch(FALSE, FALSE);
  360.             break;
  361.         case pageSetupItem:
  362.             RemoveHilitePatch();
  363.             DoThePageSetup();
  364.             InstallHilitePatch();
  365.             break;
  366.         case printItem:
  367.             theWindow=GetFrontDocumentWindow();
  368.             if (WindowHasLayer(theWindow))
  369.             {
  370.                 hTE=GetWindowTE(theWindow);
  371.                 if (hTE!=0L)
  372.                 {
  373.                     RemoveHilitePatch();
  374.                     PrintText(hTE);
  375.                     InstallHilitePatch();
  376.                 }
  377.             }
  378.             else SysBeep(7);
  379.             break;
  380.         case quitItem:
  381.             gDone=ShutDownTheProgram();
  382.             break;
  383.     }
  384. }
  385.  
  386. static    void HandleEditMenu(short menuItem, Boolean alreadyPassedThrough)
  387. {
  388.     short            index;
  389.     WindowPtr        frontDoc;
  390.     enum DispatchError    resultCode;
  391.     
  392.     if (!alreadyPassedThrough)
  393.         index=gFrontWindowIndex;
  394.     else
  395.     {
  396.         frontDoc=GetFrontDocumentWindow();
  397.         index=(frontDoc!=0L) ? GetWindowIndex(frontDoc) : -1;
  398.     }
  399.     
  400.     if (index>=0)
  401.     {
  402.         switch (menuItem)
  403.         {
  404.             case undoItem:        resultCode=UndoDispatch(index);            break;
  405.             case cutItem:        resultCode=CutDispatch(index);            break;
  406.             case copyItem:        resultCode=CopyDispatch(index);            break;
  407.             case pasteItem:        resultCode=PasteDispatch(index);        break;
  408.             case clearItem:        resultCode=ClearDispatch(index);        break;
  409.             case selectAllItem:    resultCode=SelectAllDispatch(index);    break;
  410.             default:            resultCode=kSuccess;                    break;
  411.         }
  412.         
  413.         if ((resultCode==kPassThrough) && (!alreadyPassedThrough))
  414.             HandleEditMenu(menuItem, TRUE);
  415.     }
  416.     else SystemEdit(menuItem-1);
  417. }
  418.  
  419. static    void HandleOptionsMenu(short menuItem)
  420. {
  421.     WindowPtr        mainWindow;
  422.     
  423.     switch (menuItem)
  424.     {
  425.         case resolveItem:
  426.             mainWindow=GetIndWindowPtr(kMainWindow);
  427.             
  428.             if (GetFrontDocumentWindow()!=mainWindow)
  429.                 MySelectWindow(mainWindow);
  430.             
  431.             HandleError(ParserDispatch(GetIndWindowPtr(kMainWindow)), FALSE, TRUE);
  432.             break;
  433.         case alwaysResolveItem:
  434.             gAlwaysResolve=!gAlwaysResolve;
  435.             AdjustMenus();
  436.             break;
  437.         case kantinuousItem:
  438.             Kantinuous();
  439.             break;
  440.     }
  441. }
  442.  
  443. static    void HandleModulesMenu(short menuItem)
  444. {
  445.     FSSpec            theFS;
  446.     Str255            theName;
  447.     OSErr            oe;
  448.     
  449.     switch (menuItem)
  450.     {
  451.         case modules_default:
  452.             if (!gUseDefault)
  453.             {
  454.                 theFS.name[0]=0x00;
  455.                 UseTheModule(&theFS, TRUE);
  456.             }
  457.             break;
  458.         case modules_other:
  459.             if (GetSourceFile(&theFS, BUILD_TYPE))
  460.             {
  461.                 UseTheModule(&theFS, FALSE);
  462.             }
  463.             break;
  464.         case modules_unused:
  465.             break;
  466.         default:
  467.             if (NUM_MODULES>0)
  468.             {
  469.                 GetItem(gModulesMenu, menuItem, theName);
  470.                 if ((oe=GetNamedModuleFS(&theFS, theName))==noErr)
  471.                 {
  472.                     UseTheModule(&theFS, FALSE);
  473.                 }
  474.                 else
  475.                 {
  476.                     HandleError(kModuleNotFound, FALSE, FALSE);
  477.                 }
  478.             }
  479.             break;
  480.     }
  481. }
  482.  
  483. static    void HandleInsertMenu(short menuItem)
  484. {
  485.     WindowPtr        mainWindow;
  486.     Str255            theName, fullName;
  487.     
  488.     mainWindow=GetIndWindowPtr(kMainWindow);
  489.     if (mainWindow==0L)
  490.     {
  491.         OpenTheIndWindow(kMainWindow);
  492.         mainWindow=GetIndWindowPtr(kMainWindow);
  493.     }
  494.     
  495.     if (GetFrontDocumentWindow()!=mainWindow)
  496.         MySelectWindow(mainWindow);
  497.     
  498.     if (gUseDefault)
  499.     {
  500.         switch (menuItem)
  501.         {
  502.             case sectionItem:
  503.                 InsertAfterEnd(mainWindow, "\p§ion");
  504.                 break;
  505.             case paragraphItem:
  506.                 InsertAfterEnd(mainWindow, "\p¶graph");
  507.                 break;
  508.             case sentenceItem:
  509.                 InsertAfterEnd(mainWindow, "\p&sentence");
  510.                 break;
  511.             case mainClauseItem:
  512.                 InsertAfterEnd(mainWindow, "\p&main-clause");
  513.                 break;
  514.             case introClauseItem:
  515.                 InsertAfterEnd(mainWindow, "\p&intro-clause");
  516.                 break;
  517.             case throwawayClauseItem:
  518.                 InsertAfterEnd(mainWindow, "\p&throwaway-clause");
  519.                 break;
  520.             case proofItem:
  521.                 InsertAfterEnd(mainWindow, "\p&proof");
  522.                 break;
  523.             case throwawaySentenceItem:
  524.                 InsertAfterEnd(mainWindow, "\p&throwaway-sentence");
  525.                 break;
  526.         }
  527.     }
  528.     else
  529.     {
  530.         GetItem(gInsertMenu, menuItem, theName);
  531.         fullName[0]=0x01;
  532.         fullName[1]='&';
  533.         AppendStr255(fullName, theName);
  534.         InsertAfterEnd(mainWindow, fullName);
  535.     }
  536.     
  537.     if (gAlwaysResolve)
  538.         HandleError(ParserDispatch(GetIndWindowPtr(kMainWindow)), FALSE, TRUE);
  539. }
  540.  
  541. static    void HandleBuildMenu(short menuItem)
  542. {
  543.     FSSpec            theFS;
  544.     WindowPtr        buildWindow;
  545.     OSErr            oe;
  546.     
  547.     buildWindow=GetIndWindowPtr(kBuildWindow);
  548.     if ((buildWindow!=0L) && (GetFrontDocumentWindow()!=buildWindow))
  549.     {
  550.         MySelectWindow(buildWindow);
  551.         SetCursor(&qd.arrow);
  552.     }
  553.     
  554.     switch (menuItem)
  555.     {
  556.         case build_new:
  557.             oe=DoNewModule();
  558.             if ((oe!=noErr) && (oe!=-1))    /* -1 = user cancel */
  559.                 HandleError(kCantCreateNewModule, FALSE, FALSE);
  560.             break;
  561.         case build_open:
  562.             oe=OpenTheModule(&theFS, FALSE, FALSE);
  563.             if ((oe!=noErr) && (oe!=-1))
  564.             {
  565.                 if (oe==-2)
  566.                     HandleError(kModuleTooLarge, FALSE, FALSE);
  567.                 else
  568.                     HandleError(kCantOpenModule, FALSE, FALSE);
  569.             }
  570.             break;
  571.         case build_new_ref:
  572.             DoNewRef(buildWindow);
  573.             break;
  574.         case build_new_instant:
  575.             DoNewInstantiation(buildWindow);
  576.             break;
  577.         case build_edit_ref:
  578.             if (RefHighlightedQQ(buildWindow))
  579.                 DoEditRef(buildWindow);
  580.             else
  581.                 DoEditInstantiation(buildWindow);
  582.             break;
  583.         case build_delete_ref:
  584.             if (RefHighlightedQQ(buildWindow))
  585.                 DoDeleteRef(buildWindow);
  586.             else
  587.                 DoDeleteInstantiation(buildWindow);
  588.             break;
  589.         case build_show_instant:
  590.             DealWithArrowClick(buildWindow, CurrentLineNumber(GetWindowTE(buildWindow)));
  591.             break;
  592.         case build_show_all_instant:
  593.             DoShowHideAll(buildWindow, TRUE);
  594.             break;
  595.         case build_hide_all_instant:
  596.             DoShowHideAll(buildWindow, FALSE);
  597.             break;
  598.     }
  599. }
  600.  
  601. static    void HandleSpeedMenu(short menuItem)
  602. {
  603.     switch (menuItem)
  604.     {
  605.         case delay0Item:
  606.             gSpeedDelay=0;
  607.             break;
  608.         case delay6Item:
  609.             gSpeedDelay=6;
  610.             break;
  611.         case delay12Item:
  612.             gSpeedDelay=12;
  613.             break;
  614.         case delay30Item:
  615.             gSpeedDelay=30;
  616.             break;
  617.         case delay60Item:
  618.             gSpeedDelay=60;
  619.             break;
  620.     }
  621.     
  622.     AdjustMenus();
  623. }
  624.  
  625. static    void EDItem(MenuHandle theMenu, short theItem, Boolean theCondition)
  626. {
  627.     if (theCondition)
  628.         EnableItem(theMenu, theItem);
  629.     else
  630.         DisableItem(theMenu, theItem);
  631. }
  632.  
  633. void RebuildModulesList(void)
  634. {
  635.     FSSpec            theFS;
  636.     
  637.     DeleteMenu(modulesMenu);
  638.     gModulesMenu=(MenuHandle)SafeReleaseResource((Handle)gModulesMenu);
  639.     gModulesMenu=GetMenu(modulesMenu);
  640.     InsertMenu(gModulesMenu, insertMenu);
  641.     if (BuildModulesList(gModulesMenu)!=noErr)
  642.     {
  643.         HandleError(kCantFindModulesFolder, FALSE, FALSE);
  644.         theFS.name[0]=0x00;
  645.         UseTheModule(&theFS, TRUE);    /* revert to built-in */
  646.     }
  647. }
  648.  
  649. void RebuildReferencesList(void)
  650. {
  651.     short            i;
  652.     FSSpec            theFS;
  653.     
  654.     gInsertMenu=(MenuHandle)SafeReleaseResource((Handle)gInsertMenu);
  655.     gInsertMenu=GetMenu(insertMenu);
  656.     InsertMenu(gInsertMenu, buildMenu);
  657.     if (!gUseDefault)
  658.     {
  659.         for (i=CountMItems(gInsertMenu); i>0; i--)
  660.             DelMenuItem(gInsertMenu, i);
  661.         if (BuildReferencesList(gInsertMenu, gModuleFS)!=noErr)
  662.         {
  663.             HandleError(kCantBuildReferenceList, FALSE, FALSE);
  664.             theFS.name[0]=0x00;
  665.             UseTheModule(&theFS, TRUE);    /* revert to built-in */
  666.         }
  667.     }
  668. }
  669.